package com.example.project.service;

import com.example.project.dao.MaterialInterface;
import com.example.project.entity.Material;
import com.example.project.entity.ResponseInfo;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Service
public class MaterialService {
    @Resource
    MaterialInterface materialInterface;
    public ResponseInfo materialtable(Material material) {
        List<Material> materiaList = materialInterface.materialtable(material);
        Map<String, Object> map = new HashMap<>();
        map.put("rows", materiaList);

        return ResponseInfo.success(map);
    }

    public ResponseInfo addtable(Material material){
        if(StringUtils.hasLength(material.getName()) )
        {
            materialInterface.addtable(material);
            return ResponseInfo.success(null);}
        else {
            return ResponseInfo.fail(300,"填写为空");
        }}

    public ResponseInfo edittable(Material material) {
        if(StringUtils.hasLength(material.getName()) )
        {
            materialInterface.edittable(material);
            return ResponseInfo.success(null);}
        else {
            return ResponseInfo.fail(300,"填写为空");
        }}

    public ResponseInfo deltable(Material material) {
        long count=materialInterface.counttablepid(material);
        if (count>0){
            return ResponseInfo.fail(300,"有下级菜单");

        }else {
            materialInterface.deltable(material);
            return ResponseInfo.success(null);
        }

    }
}
